# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Joakim Hernberg <jhernberg@alchemy.lu>

pkgname=python-inet_diag
pkgver=0.2.1
pkgrel=8
pkgdesc="Python bindings for the inet_diag kernel interface"
arch=('loong64' 'x86_64')
url="https://git.kernel.org/pub/scm/libs/python/python-inet_diag/python-inet_diag.git/"
license=('GPL2')
depends=('python')
makedepends=('python-setuptools')
source=("https://git.kernel.org/pub/scm/libs/python/${pkgname}/${pkgname}.git/snapshot/${pkgname}-${pkgver}.tar.gz"
        "${pkgname}-0.2.1-remove_legacy_struct_member.patch")
sha512sums=('fe9c5a51d0b29abdb765990db37ab6f399aa5f46fa068655892181fea413d41a07486af7509540518a765d03fb4981a8a8784e5aa8b0367bb65bc36ef136be32'
            '9a49dc11035fa22bc15f5172615a74d25925a807201be1cec33db775635a84b6411f03a3365d5e45479d229c69496c45ab87caa5cfd582ff0bd84c41ed86e160')
b2sums=('2c741c1b31e7d67db837d30982e19ad038715c067a13e945d8585eaeb90142f45d6646814c346033c846c436de6beae7ee5f69d3a1649393ba6ec05a89a44fc7'
        '3ae80258dea549d3ade8cd01a82a4b2559a9a120b8bdd7dc331b984b9d3fd6991d2f23ac6df7bf60c2357a59be98a066173fc554d8c6b1000e1bf2b76af44d9b')

prepare() {
  cd "${pkgname}-${pkgver}"
  sed -e '1s/python2/python/' -i setup.py
  # Removed in Python 3.9. Ignored in Python 3.0+ anyway.
  patch -Np1 -i "../${pkgname}-0.2.1-remove_legacy_struct_member.patch"
}

build() {
  cd "${pkgname}-${pkgver}"
  python setup.py build
}

package_python-inet_diag() {
  cd "${pkgname}-${pkgver}"
  python setup.py install --skip-build \
                          --optimize=1 \
                          --root="${pkgdir}/"
  install -vDm 775 psk.py "${pkgdir}/usr/bin/psk"
  install -vDm 775 pss.py "${pkgdir}/usr/bin/pss"
}
